package com.hzqy.web.tag;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hzqy.commons.utils.ConstantUtils;
import com.hzqy.web.vo.PmsAttributeVo;

public class PmsUiAuthTag extends TagSupport{
	private static final Logger LOG = LoggerFactory.getLogger(PmsUiAuthTag.class);
	private String url;
	private static String uiRights;
	
	public int doStartTag() throws JspTagException {
		if(uiRights == null) {
			uiRights = this.pageContext.getServletContext().getInitParameter("uiRights");
		}
		if(uiRights.equalsIgnoreCase("false")) { //调试模试
			return EVAL_BODY_INCLUDE;
		} else {
			HttpSession session = this.pageContext.getSession();
			List<PmsAttributeVo> pavList = (List<PmsAttributeVo>) session.getAttribute(ConstantUtils.SESSION_ATTRIBUTE);
			Iterator<PmsAttributeVo> attIter = pavList.iterator();
			int flag = 0;
			while(attIter.hasNext()) {
				String attUrl = attIter.next().getF_pa_url();
				if(attUrl.trim().equals(url.trim())) {
					flag = 1;
					break;
				}
			}
			if(flag == 1) {
				return EVAL_BODY_INCLUDE;
			} else {
				return SKIP_BODY;
			}
		}
	}
	public int doEndTag() throws JspTagException {
		return EVAL_PAGE;
	}
	
	public void setUrl(String url) {
		this.url = url;
	}
}
